timeUtils = 
  #获取当前时间的年月日时分秒毫秒
  getTime:(date)->
    year = date.getFullYear()
    month = date.getMonth()+1
    day = date.getDate()
    hour = date.getHours()
    minute = date.getMinutes()
    second = date.getSeconds()
    ms = date.getMilliseconds()
    if month < 10
      month = '0' + month
    if day < 10
      day = '0' + day
    if hour < 10
      hour = '0' + hour
    if minute < 10
      minute = '0' + minute
    if second < 10
      second = '0' + second
    return ""+ year + '年' + month + '月' + day + '日'

  # 获取日期格式为yyyy-mm-dd
  getDateString:(date)->
    year = date.getFullYear()
    month = date.getMonth()+1
    day = date.getDate()
    if month < 10
      month = '0' + month
    if day < 10
      day = '0' + day
    return ""+ year + '-' + month + '-' + day

  # 获取日期格式为yyyymmdd
  getDateString2:(date)->
    year = date.getFullYear()
    month = date.getMonth()+1
    day = date.getDate()
    if month < 10
      month = '0' + month
    if day < 10
      day = '0' + day
    return ""+ year + month + day

  #获取当前时间的时分秒
  getTime2:(date)->
    hour = date.getHours()
    minute = date.getMinutes()
    second = date.getSeconds()

    if hour < 10
      hour = '0' + hour
    if minute < 10
      minute = '0' + minute
    if second < 10
      second = '0' + second
    return ""+ hour + minute + second

  # yyyy-mm-dd转为整形
  changeDateToNumber: (date) ->
    dateArr = date?.split '-'
    dateStr = dateArr?.join ''
    dateInt = parseInt dateStr
    dateInt

  # 比较yyyy-mm-dd两个日期的大小
  compareTime: (d1,d2) ->
    if not d2
      if 10 isnt d1?.length
        return '日期不合法'
      return true

    if 10 isnt d1?.length or 10 isnt d2?.length
      return '日期不合法'
    date1 = timeUtils.changeDateToNumber d1
    date2 = timeUtils.changeDateToNumber d2
    if date1 > date2
      return '日期不合法'
    true

  # 比较yyyy-mm-dd两个日期的大小
  compareTime2: (d1,d2) ->
    if not d2
      if 10 isnt d1?.length
        return '日期不合法'
      return true

    if 10 isnt d1?.length or 10 isnt d2?.length
      return '日期不合法'
    date1 = timeUtils.changeDateToNumber d1
    date2 = timeUtils.changeDateToNumber d2
    if date1 >= date2
      return '日期不合法'
    true

module.exports = timeUtils